package com.ruoyi.document.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.document.domain.DocHighBankContent;
import com.ruoyi.document.service.DocHighBankContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.document.mapper.DocHighBankMapper;
import com.ruoyi.document.domain.DocHighBank;
import com.ruoyi.document.service.IDocHighBankService;

/**
 * 高级题管理Service业务层处理
 *
 * @author tom
 * @date 2024-12-04
 */
@Service
public class DocHighBankServiceImpl implements IDocHighBankService
{
    @Autowired
    private DocHighBankMapper docHighBankMapper;
    @Autowired
    private DocHighBankContentService docHighBankContentService;

    /**
     * 查询高级题管理
     *
     * @param id 高级题管理主键
     * @return 高级题管理
     */
    @Override
    public DocHighBank selectDocHighBankById(Long id)
    {
        DocHighBank docHighBank = docHighBankMapper.selectDocHighBankById(id);
        DocHighBankContent highBankContent = docHighBankContentService.findContentById(String.valueOf(docHighBank.getId()));
        docHighBank.setContent(docHighBank.getContent());
        return docHighBank;
    }

    /**
     * 查询高级题管理列表
     *
     * @param docHighBank 高级题管理
     * @return 高级题管理
     */
    @Override
    public List<DocHighBank> selectDocHighBankList(DocHighBank docHighBank)
    {
        return docHighBankMapper.selectDocHighBankList(docHighBank);
    }

    /**
     * 新增高级题管理
     *
     * @param docHighBank 高级题管理
     * @return 结果
     */
    @Override
    public int insertDocHighBank(DocHighBank docHighBank)
    {
        docHighBank.setCreateTime(DateUtils.getNowDate());
        int i = docHighBankMapper.insertDocHighBank(docHighBank);
        DocHighBankContent docHighBankContent = new DocHighBankContent();
        docHighBankContent.setId(String.valueOf(docHighBank.getId()));
        docHighBankContent.setContent(docHighBank.getContent());
        docHighBankContentService.saveContent(docHighBankContent);
        return i;
    }

    /**
     * 修改高级题管理
     *
     * @param docHighBank 高级题管理
     * @return 结果
     */
    @Override
    public int updateDocHighBank(DocHighBank docHighBank)
    {
        docHighBank.setUpdateTime(DateUtils.getNowDate());
        int i = docHighBankMapper.updateDocHighBank(docHighBank);
        DocHighBankContent docHighBankContent = new DocHighBankContent();
        docHighBankContent.setId(String.valueOf(docHighBank.getId()));
        docHighBankContent.setContent(docHighBank.getContent());
        docHighBankContentService.updateContent(docHighBankContent);
        return i;
    }

    /**
     * 批量删除高级题管理
     *
     * @param ids 需要删除的高级题管理主键
     * @return 结果
     */
    @Override
    public int deleteDocHighBankByIds(Long[] ids)
    {
        int i = docHighBankMapper.deleteDocHighBankByIds(ids);
        for (Long id : ids) {
            docHighBankContentService.deleteContentById(String.valueOf(id));
        }
        return i;
    }

    /**
     * 删除高级题管理信息
     *
     * @param id 高级题管理主键
     * @return 结果
     */
    @Override
    public int deleteDocHighBankById(Long id)
    {
        int i = docHighBankMapper.deleteDocHighBankById(id);
        docHighBankContentService.deleteContentById(String.valueOf(id));
        return i;
    }
}
